//
//  CMDBResultMovieCell.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/5/2.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

private let eachLineMargin : CGFloat = 9

class CMDBResultMovieCell: CustomBaseCell {
    
    var coverImageView : UIImageView = UIImageView.getInstance()
    
    var nameLabel : UILabel          = UILabel.getInstance()
    
    var disticDicLabel : UILabel     = UILabel.getInstance()
    
    var boxOfficeLabel : UILabel     = UILabel.getInstance()
    
    var categoryLabel : UILabel      = UILabel.getInstance()
    
    var publishDataLabel : UILabel   = UILabel.getInstance()
    
    var durationLabel : UILabel      = UILabel.getInstance()
    
    var showTagLabel : UILabel       = UILabel.getInstance()
    
    override func setupCell() {
        super.setupCell()
        
        backgroundColor = UIColor.whiteColor()
    }
    
    override func cellBuildSubViews() {
        super.cellBuildSubViews()
        
        coverImageView.frame  = CGRect(x: 15, y: 15, width: 190 * CMDB_Rate, height: 126 * 2 * CMDB_Rate)
        
        coverImageView.image  = UIImage(named: "相册背景图")
        
        contentView.addSubview(coverImageView)
        
        let testStr           = "狼图腾"
        
        let size              = testStr.suitToSize(CGSize(width: 100, height: 999), boldFontSize: 17, lineSpacing: 1)
        
        nameLabel.text        = testStr
        
        nameLabel.font        = CMDB_17_Bold_FONT
        
        nameLabel.textColor   = word87Color
        
        nameLabel.frame       = CGRect(x: CGRectGetMaxX(self.coverImageView.frame) + KleftMargin, y: KleftMargin, width: 100, height: size.height)
        
        contentView.addSubview(nameLabel)
        
        let testDisticStr     = "地区: "
        
        let sizeDic           = testDisticStr.suitToSize(CGSize(width: 100, height: 999), fontSize: 13, lineSpacing: 0)
        
        disticDicLabel.font   = CMDB_13_FONT
        
        disticDicLabel.textColor = word87Color
        
        disticDicLabel.text   = testDisticStr.stringByAppendingString("中国大陆")
        
        disticDicLabel.frame  = CGRect(x: CGRectGetMinX(nameLabel.frame), y: CGRectGetMaxY(nameLabel.frame) + eachLineMargin, width: 100, height: sizeDic.height)
        
        contentView.addSubview(disticDicLabel)
        
        boxOfficeLabel.text   = "票房: "
        
        boxOfficeLabel.font   = CMDB_13_FONT
        
        boxOfficeLabel.text   = boxOfficeLabel.text?.stringByAppendingString("3.2亿")
        
        boxOfficeLabel.frame  = CGRect(x: nameLabel.frame.origin.x, y: CGRectGetMaxY(disticDicLabel.frame) + eachLineMargin, width: 100, height: sizeDic.height)
        
        contentView.addSubview(boxOfficeLabel)
        
        categoryLabel.text    = "类型: "
        
        categoryLabel.textColor = word87Color
        
        categoryLabel.font      = CMDB_13_FONT
        
        categoryLabel.frame     = CGRect(x: nameLabel.frame.origin.x, y: CGRectGetMaxY(boxOfficeLabel.frame) + eachLineMargin, width: 100, height: sizeDic.height)
        
        contentView.addSubview(categoryLabel)
        
        publishDataLabel.textColor = word87Color
        
        publishDataLabel.text      = "上映日期: "
        
        publishDataLabel.text      = publishDataLabel.text?.stringByAppendingString("2016-08-30")
        
        publishDataLabel.font      = disticDicLabel.font
        
        publishDataLabel.textColor = word87Color
        
        publishDataLabel.frame     = CGRect(x: nameLabel.frame.origin.x, y: CGRectGetMaxY(categoryLabel.frame) + eachLineMargin, width: 200, height: sizeDic.height)
        
        contentView.addSubview(publishDataLabel)
        
        durationLabel.text         = "片长: "
        
        durationLabel.text         = durationLabel.text?.stringByAppendingString("130分钟")
        
        durationLabel.textColor     = word87Color
        
        durationLabel.font          = disticDicLabel.font
        
        durationLabel.frame     = CGRect(x: nameLabel.frame.origin.x, y: CGRectGetMaxY(publishDataLabel.frame) + eachLineMargin, width: 100, height: sizeDic.height)
        
        contentView.addSubview(durationLabel)
    }
    
    override func loadContent() {
        
    }
    
    
    override func setHighlighted(highlighted: Bool, animated: Bool) {
        
        UIView.animateWithDuration(0.35, delay: 0, options: .BeginFromCurrentState, animations: {
            self.nameLabel.x  = (highlighted == true ? CGRectGetMaxX(self.coverImageView.frame) + KleftMargin + 4 : CGRectGetMaxX(self.coverImageView.frame) + KleftMargin)
            self.backgroundColor  = (highlighted == true ? UIColor.randomColor().colorWithAlphaComponent(0.1) : UIColor.whiteColor())
            }, completion: nil)
    }


}
